home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / idt.zip / IDT.H < prev    next >
C/C++ Source or Header  |  1988-06-12  |  9KB  |  306 lines

  1. /*
  2. **    file:        idt.h
  3. **
  4. **    purpose:    This file contains the format of DOS' internal
  5. **            data table which may be located via the un-
  6. **            documented function call 52h.
  7. **
  8. **            This information has been gathered from many
  9. **            sources, including public bulletin boards,
  10. **            magazine articles, books, and personal
  11. **            exploration.  One significant source of the
  12. **            structure of this mess is Jim Kyle. Through
  13. **            his program CVTTRC, downloaded from Compuserve,
  14. **            many holes were filled.
  15. **
  16. **    author:        Bill Parrott
  17. **
  18. **            Copyright (c) 1988, Bill Parrott
  19. **              All Rights Reserved
  20. */
  21.  
  22. #pragma    pack(1)
  23.  
  24. /*
  25. **    type definitions
  26. */
  27.  
  28. typedef    unsigned char    byte;
  29. typedef    unsigned int    word;
  30. typedef    unsigned long    dword;
  31. typedef    unsigned int    segment;
  32.  
  33. typedef    struct idt    IDT;
  34. typedef    struct devhdr    DEVHDR;
  35. typedef    struct pdpt    PDPT;
  36. typedef    struct ldt    LDT;
  37. typedef    struct mdb    MDB;
  38. typedef    struct bcb    BCB;
  39. typedef    struct chain    CHAIN;
  40. typedef    struct ifcb    IFCB;
  41. typedef    struct time    TIME;
  42. typedef    struct date    DATE;
  43. typedef    struct psp    PSP;
  44.  
  45.  
  46.  
  47. /*
  48. **    This structure defines a device driver header.  Device drivers
  49. **    are linked in a chain by MS-DOS during system boot up.  The
  50. **    sequence of this linkage is:
  51. **
  52. **        NUL
  53. **        <installable device drivers>
  54. **        CON
  55. **        AUX
  56. **        PRN
  57. **        CLOCK$
  58. **
  59. **    Installable device drivers are loaded and appear in the
  60. **    sequence encountered in CONFIG.SYS.  The NUL device
  61. **    header is listed as part of the internal data table
  62. **    (below) and may be used as a starting point in the list.
  63. */
  64.  
  65. struct devhdr
  66.     {
  67.     DEVHDR    far *nextheader;    /* address of next header    */
  68.     word    attributes;        /* device attributes        */
  69.     word    strategy;        /* strategy entry point        */
  70.     word    intrupt;        /* interrupt entry point    */
  71.     byte    devname[8];        /* device name            */
  72.     };
  73.  
  74.  
  75.  
  76.  
  77. /*
  78. **    This is the definition of the internal data table.  Its
  79. **    address may be found by subtracting 8 from the value
  80. **    returned in (bx) from DOS function 52h and combining
  81. **    that offset with the segment returned in (es).
  82. **
  83. **    This table format is not correct for versions of DOS
  84. **    prior to 3.0.
  85. */
  86.  
  87. struct idt
  88.     {
  89.     BCB    far *curbcb;        /* address of current buffer        */
  90.     MDB    far *arena;        /* start of memory arena        */
  91.     PDPT    far *pdpt;        /* physical drive parameter table    */
  92.     CHAIN    far *ifcb;        /* internal file control blocks        */
  93.     void    far *clockdev;        /* address of clock device driver    */
  94.     void    far *condev;        /* address of console device driver    */
  95.     word    max_ssize;        /* maximum allowed sector size        */
  96.     BCB    far *bcbhead;        /* start of buffer list            */
  97.     LDT    far *ldt;        /* address of logical device table    */
  98.     CHAIN    far *fcbt;        /* file control block table        */
  99.     word    nprotfcbs;        /* number of protected fcbs (FCBS=?,n)    */
  100.     byte    nphysdrives;        /* number of physical devices        */
  101.     byte    nlogdrives;        /* number of logical devices (in ldt)    */
  102.     DEVHDR    nuldev;            /* NUL device header            */
  103.     };
  104.  
  105.  
  106.  
  107.  
  108. /*
  109. **    This structure defines the physical device table.  An
  110. **    individual entry in the table may be obtained by calling
  111. **    DOS interrupt 21H with function 32H, (dl) set to the
  112. **    drive desired (0=default, 1=A, 2=B, ...).  Returned
  113. **    value in (al) = FFH if the drive does not exist, else
  114. **    00H, ds:bx points to the desired entry.
  115. **
  116. **    The head of the physical device table may be found in
  117. **    the internal data table, described above.
  118. */
  119.  
  120. struct pdpt
  121.     {
  122.     byte    drive;            /* Drive: 0=A, 1=B, etc.    */
  123.     byte    dunit;            /* Unit within driver (0,1,...)    */
  124.     word    sectorsize;        /* bytes per sector        */
  125.     byte    clustersize;        /* sectors per cluster - 1    */
  126.     byte    shift;            /* cluster to sector shift    */
  127.     word    bootsectors;        /* number of reserved sectors    */
  128.     byte    fats;            /* number of file alloc. tables    */
  129.     word    rootsize;        /* number of root dir. entries    */
  130.     word    dataoffset;        /* sector # of cluster 2 (data)    */
  131.     word    lastcluster;        /* number of clusters + 1    */
  132.     byte    fatsize;        /* sectors for FAT        */
  133.     word    diroffset;        /* sector number of directory    */
  134.     DEVHDR    far *devheader;        /* address of device header    */
  135.     byte    mediabyte;        /* media descriptor byte    */
  136.     byte    accessflag;        /* 0 if disk has been accessed    */
  137.     PDPT    far *nextentry;        /* address of next entry    */
  138.     };
  139.  
  140.  
  141. /*
  142. **    This structure defines the logical device table.  This
  143. **    table is utilized by MS-DOS to keep track of logical
  144. **    drives.  The number of entries in the table is kept
  145. **    in the internal device table (above) in nlogdrives.
  146. **    The number of logical drives is set to the higher
  147. **    of LASTDRIVE= in CONFIG.SYS or the number of physical
  148. **    drives.
  149. **
  150. **    Some general observations (not necessarily rules!!):
  151. **
  152. **    code == 00 if logical device is invalid
  153. **    code == 40 if logical device directly associated with physical device
  154. **    code == 50 if logical device is SUBST'ed
  155. **
  156. **    flag == 001b if drive is SUBST'ed
  157. */
  158.  
  159. struct ldt
  160.     {
  161.     char    currentdir[68];        /* current directory for this drive    */
  162.     byte    code;            /* ??  00, 40 or 50            */
  163.     PDPT    far *pdpt;        /* physical device for this logical dev    */
  164.     word    curdir;            /* directory sector            */
  165.     word    fubar[2];        /* ??  FFFFh FFFFh            */
  166.     word    flag;            /* ??  0002, 0008, 001b            */
  167.     };
  168.  
  169.  
  170.  
  171. /*
  172. **    This structure defines a memory descriptor.  These are used
  173. **    by MS-DOS to keep track of allocated memory.  The address
  174. **    of the first descriptor is found in the idt (above).
  175. */
  176.  
  177. struct mdb
  178.     {
  179.     byte    type;            /* 'M' if descriptor, 'Z' if last one    */
  180.     segment    owner;            /* PSP of owner                */
  181.     word    length;            /* length of this block (paragraphs)    */
  182.     };
  183.  
  184.  
  185.  
  186. /*
  187. **    This structure defines the buffer control block. The
  188. **    information here is incomplete because it comes entirely
  189. **    from CVTTRC.C.
  190. */
  191.  
  192. struct bcb
  193.     {
  194.     BCB    far *nextbcb;        /* address of next BCB            */
  195.     byte    logdrive;        /* logical drive associated with buffer    */
  196.     byte    action;            /* action code                */
  197.     word    logsec;            /* logical sectoe #            */
  198.     byte    nfats;            /* # of FATs                */
  199.     byte    sectorsperfat;        /* sectors per FAT            */
  200.     PDPT    far *pdpt;        /* pdpt associated with buffer        */
  201.     word    fubar;            /* ?? (probably filler to align buffer)    */
  202.     byte    buffer[512];        /* the buffer                */
  203.     };
  204.  
  205.  
  206. /*
  207. **    This structure is used to define the length of a chain of
  208. **    internal file control blocks.  By itself, it really does
  209. **    nothing, however it provides the mechanism for locating
  210. **    IFCBs.
  211. */
  212.  
  213. struct chain
  214.     {
  215.     CHAIN    far *nextchain;        /* link to next chain            */
  216.     word    nentries;        /* number of entries in this link    */
  217.     };
  218.  
  219.  
  220.  
  221. /*
  222. **    This structure defines the internal file control block
  223. **    used by MS-DOS to track open files.  The total number of
  224. **    these in the internal file control block chain is determined
  225. **    by FILES= in CONFIG.SYS.  The total number of these in the
  226. **    FCB table chain is determined by FCBS= in CONFIG.SYS.
  227. */
  228.  
  229. struct date
  230.     {
  231.     unsigned day    : 5;        /* day (1-31)                */
  232.     unsigned month    : 4;        /* month (1-12)                */
  233.     unsigned year    : 7;        /* 1980 - year (0-127)            */
  234.     };
  235.  
  236.  
  237. struct time
  238.     {
  239.     unsigned second    : 5;        /* seconds / 2 (0-29)            */
  240.     unsigned minute    : 6;        /* minute (0-59)            */
  241.     unsigned hour    : 5;        /* hour (0-23)                */
  242.     };
  243.  
  244.  
  245. struct ifcb
  246.     {
  247.     word    nopens;            /* # opens active            */
  248.     word    mode;            /* open mode, 0=read, 1=write, 2=r/w    */
  249.     byte    fileattr;        /* file attribute (flags) byte        */
  250.     word    devattr;        /* device attribute word        */
  251.     PDPT    far *pdpt;        /* pdpt associated with file        */
  252.     word    firstcluster;        /* 1st cluster of file            */
  253.     TIME    filetime;        /* file time                */
  254.     DATE    filedate;        /* file date                */
  255.     dword    filesize;        /* file size (bytes)            */
  256.     dword    filepos;        /* current file position        */
  257.     word    nclusters;        /* # of clusters in file        */
  258.     word    curcluster;        /* current cluster            */
  259.     word    dirsector;        /* directory sector            */
  260.     byte    dirindex;        /* index in directory sector        */
  261.     byte    filename[8];        /* file name                */
  262.     byte    fileext[3];        /* file type (extension)        */
  263.     word    fubar[3];        /* ???                    */
  264.     segment    owner;            /* PSP of file owner            */
  265.     word    fubar2;            /* ???                    */
  266.     };
  267.  
  268.  
  269.  
  270. /*
  271. **    This structure define the program segment prefix.  There
  272. **    is a PSP associated with every process executing under
  273. **    MS-DOS.  Note that in this definition, the FCB's are not